package leetcode.other.p283;

import java.util.Arrays;

class Solution2 {
    public void moveZeroes(int[] nums) {
        int cnt = 0;
        for (int i = 0, j = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j++] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        //示例 1:
        //输入: nums = [0,1,0,3,12]
        //输出: [1,3,12,0,0]
        int[] nums = new int[]{0, 1, 0, 3, 12};
        Solution2 s = new Solution2();
        s.moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
        //示例 2:
        //输入: nums = [0]
        //输出: [0]
        int[] nums2 = new int[]{0};
        s.moveZeroes(nums2);
        System.out.println(Arrays.toString(nums2));
    }
}